/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import vn.com.fis.portal.model.ContactEntry;
import vn.com.fis.portal.model.ContactEntryModel;
import vn.com.fis.portal.model.ContactEntrySoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.List;

/**
 * The base model implementation for the ContactEntry service. Represents a row in the &quot;TBL_CONTACT&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link vn.com.fis.portal.model.ContactEntryModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link ContactEntryImpl}.
 * </p>
 *
 * @author loind
 * @see ContactEntryImpl
 * @see vn.com.fis.portal.model.ContactEntry
 * @see vn.com.fis.portal.model.ContactEntryModel
 * @generated
 */
@JSON(strict = true)
public class ContactEntryModelImpl extends BaseModelImpl<ContactEntry>
	implements ContactEntryModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a contact entry model instance should use the {@link vn.com.fis.portal.model.ContactEntry} interface instead.
	 */
	public static final String TABLE_NAME = "TBL_CONTACT";
	public static final Object[][] TABLE_COLUMNS = {
			{ "contactId", Types.BIGINT },
			{ "contactName", Types.VARCHAR },
			{ "mobileNumber", Types.VARCHAR },
			{ "userId", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table TBL_CONTACT (contactId LONG not null primary key,contactName VARCHAR(75) null,mobileNumber VARCHAR(75) null,userId LONG)";
	public static final String TABLE_SQL_DROP = "drop table TBL_CONTACT";
	public static final String ORDER_BY_JPQL = " ORDER BY contactEntry.contactName ASC";
	public static final String ORDER_BY_SQL = " ORDER BY TBL_CONTACT.contactName ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.vn.com.fis.portal.model.ContactEntry"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.vn.com.fis.portal.model.ContactEntry"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.vn.com.fis.portal.model.ContactEntry"),
			true);
	public static long MOBILENUMBER_COLUMN_BITMASK = 1L;
	public static long USERID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static ContactEntry toModel(ContactEntrySoap soapModel) {
		ContactEntry model = new ContactEntryImpl();

		model.setContactId(soapModel.getContactId());
		model.setContactName(soapModel.getContactName());
		model.setMobileNumber(soapModel.getMobileNumber());
		model.setUserId(soapModel.getUserId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<ContactEntry> toModels(ContactEntrySoap[] soapModels) {
		List<ContactEntry> models = new ArrayList<ContactEntry>(soapModels.length);

		for (ContactEntrySoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.vn.com.fis.portal.model.ContactEntry"));

	public ContactEntryModelImpl() {
	}

	public long getPrimaryKey() {
		return _contactId;
	}

	public void setPrimaryKey(long primaryKey) {
		setContactId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_contactId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return ContactEntry.class;
	}

	public String getModelClassName() {
		return ContactEntry.class.getName();
	}

	@JSON
	public long getContactId() {
		return _contactId;
	}

	public void setContactId(long contactId) {
		_contactId = contactId;
	}

	@JSON
	public String getContactName() {
		if (_contactName == null) {
			return StringPool.BLANK;
		}
		else {
			return _contactName;
		}
	}

	public void setContactName(String contactName) {
		_columnBitmask = -1L;

		_contactName = contactName;
	}

	@JSON
	public String getMobileNumber() {
		if (_mobileNumber == null) {
			return StringPool.BLANK;
		}
		else {
			return _mobileNumber;
		}
	}

	public void setMobileNumber(String mobileNumber) {
		_columnBitmask |= MOBILENUMBER_COLUMN_BITMASK;

		if (_originalMobileNumber == null) {
			_originalMobileNumber = _mobileNumber;
		}

		_mobileNumber = mobileNumber;
	}

	public String getOriginalMobileNumber() {
		return GetterUtil.getString(_originalMobileNumber);
	}

	@JSON
	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_columnBitmask |= USERID_COLUMN_BITMASK;

		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ContactEntry toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (ContactEntry)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					ContactEntry.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		ContactEntryImpl contactEntryImpl = new ContactEntryImpl();

		contactEntryImpl.setContactId(getContactId());
		contactEntryImpl.setContactName(getContactName());
		contactEntryImpl.setMobileNumber(getMobileNumber());
		contactEntryImpl.setUserId(getUserId());

		contactEntryImpl.resetOriginalValues();

		return contactEntryImpl;
	}

	public int compareTo(ContactEntry contactEntry) {
		int value = 0;

		value = getContactName().compareTo(contactEntry.getContactName());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		ContactEntry contactEntry = null;

		try {
			contactEntry = (ContactEntry)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = contactEntry.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		ContactEntryModelImpl contactEntryModelImpl = this;

		contactEntryModelImpl._originalMobileNumber = contactEntryModelImpl._mobileNumber;

		contactEntryModelImpl._originalUserId = contactEntryModelImpl._userId;

		contactEntryModelImpl._setOriginalUserId = false;

		contactEntryModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<ContactEntry> toCacheModel() {
		ContactEntryCacheModel contactEntryCacheModel = new ContactEntryCacheModel();

		contactEntryCacheModel.contactId = getContactId();

		contactEntryCacheModel.contactName = getContactName();

		String contactName = contactEntryCacheModel.contactName;

		if ((contactName != null) && (contactName.length() == 0)) {
			contactEntryCacheModel.contactName = null;
		}

		contactEntryCacheModel.mobileNumber = getMobileNumber();

		String mobileNumber = contactEntryCacheModel.mobileNumber;

		if ((mobileNumber != null) && (mobileNumber.length() == 0)) {
			contactEntryCacheModel.mobileNumber = null;
		}

		contactEntryCacheModel.userId = getUserId();

		return contactEntryCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(9);

		sb.append("{contactId=");
		sb.append(getContactId());
		sb.append(", contactName=");
		sb.append(getContactName());
		sb.append(", mobileNumber=");
		sb.append(getMobileNumber());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(16);

		sb.append("<model><model-name>");
		sb.append("vn.com.fis.portal.model.ContactEntry");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>contactId</column-name><column-value><![CDATA[");
		sb.append(getContactId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>contactName</column-name><column-value><![CDATA[");
		sb.append(getContactName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>mobileNumber</column-name><column-value><![CDATA[");
		sb.append(getMobileNumber());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = ContactEntry.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			ContactEntry.class
		};
	private long _contactId;
	private String _contactName;
	private String _mobileNumber;
	private String _originalMobileNumber;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private ContactEntry _escapedModelProxy;
}